import __cache from '../etc/cache'

class CacheService {
  __cache

  setUserId(userId) {
    this.setValue(__cache.userId, userId);
  }
  getUserId() {
    return this.getValue(__cache.userId);
  }
  getUserInfo() {
    return this.getValue(__cache.user);
  }
  getChannel() {
    return this.getValue(__cache.channel);
  }
  setChannel(channel) {
    this.setValue(__cache.channel, channel);
  }
    setShareChannel(shareChannel) {
    this.setValue(__cache.shareChannel, shareChannel);
  }
    getShareChannel(shareChannel) {
    this.getValue(__cache.shareChannel, shareChannel);
  }

  setConfirmOrder(obj) {
    this.setValue(__cache.confirmOrder, obj);
  }
  getConfirmOrder() {
    return this.getValue(__cache.confirmOrder);
  }
  setIsChangeCart(obj) {
    this.setValue(__cache.isChangeCart, obj);
  }
  getIsChangeCart() {
    return this.getValue(__cache.isChangeCart);
  }
  removeGoodsList(classId) {
    this.removeValue('class'+classId);
  }

  setGoodsList(classId, obj) {
    this.setValue('class'+classId, obj);
  }
  getGoodsList(classId) {
    return this.getValue('class'+classId);
  }

  setToken(obj) {
    this.setValue(__cache.token, obj);
  }
  getToken() {
    return this.getValue(__cache.token);
  }
  setAddress(obj) {
    this.setValue(__cache.address, obj);
  }
  getAddress() {
    return this.getValue(__cache.address);
  }

  setAddressList(obj) {
    this.setValue(__cache.addressList, obj);
  }
  getAddressList() {
    return this.getValue(__cache.addressList);
  }
  setCarts(obj) {
    this.setValue(__cache.carts, obj);
  }
 

  setGoodsActivity(classCode,obj) {
      this.setValue(__cache.goodsActivity+classCode, obj);
  }
  getGoodsActivity(classCode) {
    return this.getValue(__cache.goodsActivity+classCode);
  }
  removeGoodsActivity(classCode) {
    this.removeValue(__cache.goodsActivity+classCode);
  }

  setGoodsTime(classId) {
    this.setValue(__cache.goodsTime + classId, new Date().getTime());
  }
  getGoodsTime(classId) {
    return this.getValue(__cache.goodsTime + classId);
  }
  removeGoodsTime(classId) {
    this.removeValue(__cache.goodsTime + classId);
  }

  setPickupAddress(obj) {
    this.setValue(__cache.pickupAddress, obj);
  }

  getPickupAddress() {
    return this.getValue(__cache.pickupAddress);
  }

  setAddressUpdateTime(obj) {
    this.setValue(__cache.addressUpdateTime, obj);
  }

  getAddressUpdateTime(obj) {
    return this.getValue(__cache.addressUpdateTime);
  }

  removeConfirmOrder() {
    this.removeValue(__cache.confirmOrder);
  }
  setOrder(obj) {
    this.setValue(__cache.carts, obj);
  }
  getOrder() {
    return this.getValue(__cache.carts);
  }
  setActivityTime(time) {
    this.setValue(__cache.activityExplainTime, time);
  }
  getActivityTime() {
    return this.getValue(__cache.activityExplainTime);
  }
  setValue(key, value) {
    wx.setStorageSync(key, value);
  }
  getValue(key) {
    return wx.getStorageSync(key);
  }
  removeValue(key) {
    wx.removeStorageSync(key);
  }
 
}
export default CacheService